#!/bin/bash

echo "=========================================="
echo "HJ212模拟客户端功能测试脚本"
echo "=========================================="
echo

# 设置基础URL
BASE_URL="http://localhost:10001"

echo "1. 测试一次性请求接口"
echo "------------------------------------------"

echo "1.1 测试发送标准数据包..."
curl -X POST "$BASE_URL/hj212/simulate/client/request?requestType=standard"
echo
echo

echo "1.2 测试发送实时数据..."
curl -X POST "$BASE_URL/hj212/simulate/client/request?requestType=realtime&pollutantCode=w01001&value=25.5"
echo
echo

echo "1.3 测试发送自定义数据包..."
curl -X POST "$BASE_URL/hj212/simulate/client/request?requestType=custom&customData=##0000ST=91;CN=9011;PW=123456;MN=00000000000000000000;Flag=5;CP=&&RtdInterval=30&&\r\n"
echo
echo

echo "2. 测试持续连接接口"
echo "------------------------------------------"

echo "2.1 连接服务器..."
curl -X POST "$BASE_URL/hj212/simulate/client/connect"
echo
echo

echo "2.2 检查连接状态..."
curl -X GET "$BASE_URL/hj212/simulate/client/status"
echo
echo

echo "2.3 发送标准数据包（保持连接）..."
curl -X POST "$BASE_URL/hj212/simulate/client/send?requestType=standard"
echo
echo

echo "2.4 发送实时数据（保持连接）..."
curl -X POST "$BASE_URL/hj212/simulate/client/send?requestType=realtime&pollutantCode=w01001&value=25.5"
echo
echo

echo "2.5 发送自定义数据包（保持连接）..."
curl -X POST "$BASE_URL/hj212/simulate/client/send?requestType=custom&customData=##0000ST=91;CN=9011;PW=123456;MN=00000000000000000000;Flag=5;CP=&&RtdInterval=30&&\r\n"
echo
echo

echo "2.6 再次检查连接状态..."
curl -X GET "$BASE_URL/hj212/simulate/client/status"
echo
echo

echo "2.7 断开连接..."
curl -X POST "$BASE_URL/hj212/simulate/client/disconnect"
echo
echo

echo "2.8 最终检查连接状态..."
curl -X GET "$BASE_URL/hj212/simulate/client/status"
echo
echo

echo "3. 测试错误情况"
echo "------------------------------------------"

echo "3.1 测试未连接时发送数据..."
curl -X POST "$BASE_URL/hj212/simulate/client/send?requestType=standard"
echo
echo

echo "3.2 测试缺少参数的实时数据请求..."
curl -X POST "$BASE_URL/hj212/simulate/client/request?requestType=realtime"
echo
echo

echo "3.3 测试不支持的请求类型..."
curl -X POST "$BASE_URL/hj212/simulate/client/request?requestType=invalid"
echo
echo

echo "=========================================="
echo "测试完成！"
echo "=========================================="
